import { defineComponent, ref, resolveComponent, openBlock, createBlock, mergeProps, withCtx, createVNode, createCommentVNode, createElementBlock, Fragment, renderList, renderSlot, createTextVNode, toDisplayString, nextTick } from "vue";
var index_vue_vue_type_style_index_0_lang = "";
const _sfc_main = /* @__PURE__ */ defineComponent({
  props: {
    showSelect: {
      type: Boolean,
      default: false
    },
    showIndex: {
      type: Boolean,
      default: false
    },
    textAlign: {
      type: String,
      default: "left"
    },
    cols: {
      type: Array,
      required: true,
      default: () => []
    },
    tableData: {
      type: Array,
      default: () => []
    },
    size: {
      type: String,
      default: "small"
    },
    operations: {
      type: Object,
      default: () => {
        return {
          show: true,
          label: ""
        };
      }
    },
    height: {
      type: String,
      default: "auto"
    },
    description: {
      type: String,
      default: "\u6682\u65E0\u6570\u636E"
    },
    primaryKey: {
      type: String,
      default: "id"
    },
    selectable: Function
  },
  setup(__props, { expose }) {
    const props = __props;
    const tableRef = ref();
    const highlight = ref(false);
    const toggleSelection = (rows) => {
      nextTick(() => {
        if (rows) {
          let selectRow = [];
          props.tableData.forEach((row) => {
            const keyValue = row[props.primaryKey];
            const index2 = rows.findIndex((item2) => item2 == keyValue);
            const item = props.tableData.find((item2) => item2[props.primaryKey] == keyValue);
            if (index2 > -1)
              selectRow.push(item);
          });
          selectRow.forEach((row) => {
            tableRef.value.toggleRowSelection(row, true);
          });
        } else {
          tableRef.value.clearSelection();
        }
      });
    };
    const clearSelection = () => {
      tableRef.value.clearSelection();
    };
    const toggleSelections = (row, status) => {
      nextTick(() => {
        tableRef.value.toggleRowSelection(row, status);
      });
    };
    expose({
      clearSelection,
      toggleSelections,
      toggleSelection
    });
    return (_ctx, _cache) => {
      const _component_el_table_column = resolveComponent("el-table-column");
      const _component_el_empty = resolveComponent("el-empty");
      const _component_el_table = resolveComponent("el-table");
      return openBlock(), createBlock(_component_el_table, mergeProps({
        ref_key: "tableRef",
        ref: tableRef,
        data: __props.tableData,
        size: __props.size,
        height: __props.height,
        "highlight-current-row": highlight.value,
        "scrollbar-always-on": "",
        class: __props.height == "auto" ? "autoHeight" : ""
      }, _ctx.$attrs), {
        empty: withCtx(() => [
          createVNode(_component_el_empty, { description: __props.description }, null, 8, ["description"])
        ]),
        default: withCtx(() => [
          __props.showSelect ? (openBlock(), createBlock(_component_el_table_column, {
            key: 0,
            type: "selection",
            "min-width": 80,
            align: __props.textAlign,
            selectable: __props.selectable
          }, null, 8, ["align", "selectable"])) : createCommentVNode("", true),
          __props.showIndex ? (openBlock(), createBlock(_component_el_table_column, {
            key: 1,
            type: "index",
            label: "\u5E8F\u53F7",
            align: __props.textAlign,
            "min-width": 80
          }, null, 8, ["align"])) : createCommentVNode("", true),
          (openBlock(true), createElementBlock(Fragment, null, renderList(__props.cols, (col) => {
            return openBlock(), createBlock(_component_el_table_column, {
              key: col.prop,
              "show-overflow-tooltip": true,
              prop: col.prop,
              width: col.width,
              "min-width": col.minWidth,
              label: col.label,
              align: __props.textAlign,
              sortable: col.sortable || false
            }, {
              default: withCtx(({ row, column, $index }) => [
                col.slot ? renderSlot(_ctx.$slots, col.prop, {
                  key: 0,
                  row,
                  column,
                  $index
                }) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                  createTextVNode(toDisplayString(row[col.prop]), 1)
                ], 64))
              ]),
              _: 2
            }, 1032, ["prop", "width", "min-width", "label", "align", "sortable"]);
          }), 128)),
          __props.operations.show ? (openBlock(), createBlock(_component_el_table_column, {
            key: 2,
            fixed: __props.operations.fixed,
            label: __props.operations.label,
            width: __props.operations.width,
            align: __props.textAlign
          }, {
            default: withCtx(({ row, column, $index }) => [
              renderSlot(_ctx.$slots, "operations", {
                row,
                column,
                $index
              })
            ]),
            _: 3
          }, 8, ["fixed", "label", "width", "align"])) : createCommentVNode("", true)
        ]),
        _: 3
      }, 16, ["data", "size", "height", "highlight-current-row", "class"]);
    };
  }
});
var index = {
  install(app) {
    app.component("bs-table", _sfc_main);
  }
};
export { index as default };
